package com.iwhalecloud.citybrain.flow.platform.manager.infrastructure.repository;


import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

import com.iwhalecloud.citybrain.flow.platform.manager.domain.model.FlowCustomTitleVo;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.repository.FlowCustomTitleRepository;
import com.iwhalecloud.citybrain.flow.platform.manager.infrastructure.entities.FlowCustomTitle;
import com.iwhalecloud.citybrain.flow.platform.manager.infrastructure.mapper.FlowTitleCustomDAO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import lombok.extern.slf4j.Slf4j;

/**
 * 　　* @description: 自定义标题配置
 * 　　* @author lzb
 * 　　* @date 2021/11/08 16:58
 */
@Slf4j
@Repository
public class FlowCustomTitleRepositoryImpl implements FlowCustomTitleRepository {

    @Autowired
    FlowTitleCustomDAO flowCustomTitleDAO;


    /**
     * 获取自定义标题表达式
     *
     * @return List<String>
     */
    @Override
    public List<String> getCustomTitleExpression() {
        return flowCustomTitleDAO.getCustomTitleExpression();
    }

    /**
     * 获取自定义标题列表
     *
     * @return Map<String, List < FlowCustomTitleVo>>
     */
    @Override
    public Map<String, List<FlowCustomTitleVo>> getCustomTitleList() {
        List<FlowCustomTitleVo> flowCustomTitleVoList = flowCustomTitleDAO.getCustomTitleList().stream().map(this::convert).collect(Collectors.toList());
        return flowCustomTitleVoList.stream().collect(Collectors.groupingBy(FlowCustomTitleVo::getTitleType));
    }


    private FlowCustomTitleVo convert(FlowCustomTitle flowCustomTitle) {
        if (Objects.isNull(flowCustomTitle)) {
            return null;
        }
        FlowCustomTitleVo result = new FlowCustomTitleVo();
        BeanUtils.copyProperties(flowCustomTitle, result);
        return result;
    }
}



